Help me, Codemonkeys on Oppo, you're my only hope...

Kinja'd!!! "Arch Duke Maxyenko, Shit Talk Extraordinaire" (arch-duke-maxyenko)
09/04/2013 at 22:15 • Filed to: help me halp me

Kinja'd!!!0 Kinja'd!!! 10

This is my stupid, stupid VB code in Excel, can you tell me where I accidentalyed? :

Private Sub Main() intNum1 = Val(InputBox("Pleas enter the first operand", "First operand")) intNum2 = Val(InputBox("Pleas enter the Second operand", "Second operand")) strMathOperation = InputBox("+, -, *, or / for the math operation", "Math operation")

Call strAddUserInput(intNum1, intNum2, strMathOperation) SendResult End Sub

Private Function strAddUserInput(intNum1 As Integer, intNum2 As Integer, strMathOperation As String) As String

Select Case strMathOperation Case "+" strAddUserInput = intNum1 + intNum2 Case "-" strAddUserInput = intNum1 - intNum2 Case "*" strAddUserInput = intNum1 * intNum2 Case "/" strAddUserInput = intNum1 / intNum2 Case Else strAddUserInput = "Invalid math operation specified" End Select End Function Private Sub SendResult() MsgBox (Str("intNum1", "strMathOperation", "intNum2" & "strAddUserInput") = vbOKOnly) End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range) Call Main End Sub


DISCUSSION (10)


Kinja'd!!! Casper > Arch Duke Maxyenko, Shit Talk Extraordinaire
09/04/2013 at 22:20

Kinja'd!!!0

I don't use Excel so I can't copy and paste it into an editor to look at. What is the error you are getting? Looking at the code I don't see anything majorly out of place other than the MsgBox syntax looks a little iffy... but it might just be because I'm use to working with .NET languages.


Kinja'd!!! dsigned001 - O.R.C. hunter > Arch Duke Maxyenko, Shit Talk Extraordinaire
09/04/2013 at 22:25

Kinja'd!!!0

Bro, do you even lif— use the next line?
I'm no genius, but does private sub let you call a variable before you've defined it? I can't see where you define strAddUserInput before you call it. It looks like you define it afterwards.


Kinja'd!!! Arch Duke Maxyenko, Shit Talk Extraordinaire > Casper
09/04/2013 at 22:26

Kinja'd!!!0

The message box is where I'm getting this:

Kinja'd!!!

with the (Str( being highlighted, should I not string function it?


Kinja'd!!! Arch Duke Maxyenko, Shit Talk Extraordinaire > dsigned001 - O.R.C. hunter
09/04/2013 at 22:29

Kinja'd!!!0

Sorry, I do separate it nicely but the copy into kinja did not jive well.

Kinja'd!!!


Kinja'd!!! Casper > Arch Duke Maxyenko, Shit Talk Extraordinaire
09/04/2013 at 22:31

Kinja'd!!!0

What are you trying to do with this statement:

MsgBox (Str("intNum1", "strMathOperation", "intNum2" & "strAddUserInput") = vbOKOnly)

I think you are doing something other than intended. It looks like you were trying to cast the 3 variables to a single string. If that is the case they should not have commas between them. You are also trying to set the string equal to a result type... I think you wanted that to be the option for the MsgBox.

Try something like this:
MsgBox("Result of " & intNum1 & strMathOperation & intNum2 & " is " & strAddUserInput, vbOkOnly, "Result Output")


Kinja'd!!! Arch Duke Maxyenko, Shit Talk Extraordinaire > Casper
09/04/2013 at 22:37

Kinja'd!!!0

Truth be told I really have know idea what I'm doing for the most part in VB just taking this mandatory class. Just trying to do challenge 3 .

I tried your line and got this:

Kinja'd!!!


Kinja'd!!! Casper > Arch Duke Maxyenko, Shit Talk Extraordinaire
09/04/2013 at 22:41

Kinja'd!!!0

Try this for the entire sub:

Private Sub SendResult()
MsgBox("Result of " & Str(intNum1) & strMathOperation & Str(intNum2) & " is " & strAddUserInput, vbOkOnly, "Result Output")
End Sub


Kinja'd!!! Arch Duke Maxyenko, Shit Talk Extraordinaire > Casper
09/04/2013 at 22:47

Kinja'd!!!0

red. red everywhere...

Kinja'd!!!


Kinja'd!!! Casper > Arch Duke Maxyenko, Shit Talk Extraordinaire
09/04/2013 at 23:07

Kinja'd!!!0

Try not surrounding the MSGBOX and using a new variable. Since I can't debug I have to guess a bit. Replace the contents of the SendResult sub with this:

strOutput = "Result of " & Str(intNum1) & strMathOperation & Str(intNum2) & " is " & strAddUserInput

MsgBox strOutput

Either one should have worked, but there must be a syntax error. Here's a review material:
http://www.excely.com/excel-vba/usin…


Kinja'd!!! Arch Duke Maxyenko, Shit Talk Extraordinaire > Casper
09/04/2013 at 23:14

Kinja'd!!!0

Still didn't work, but thanks anyways.

Have a tit for your effort:

Kinja'd!!!